/*
angle_encode.h
offer angle encode driver api
designed by lunanting

----------------------------
2020-12-28 11:43:50
create file
----------------------------
*/
#ifndef __ANGLE_ENCODE_H
#define __ANGLE_ENCODE_H

#include "../../bsp/bsp.h"

/*****************************************data type define**********************************/

#define ADDR_BRT38R0M_SINGLE_COUNT	0x0003
#define ADDR_BRT38R0M_MULT_COUNT	0x0002

#define ADDR_SE100T40_SINGLE_COUNT	0x0000

typedef enum{
	SENS_BRT38R0M,
	SENS_SE100T40,
}Type_Sens_Type_Def;

typedef struct{
	uint8_t 	slave_id;    		//modbus slave id
	uint8_t 	port;    			//modbus uart port
    uint32_t 	speed;   			//modbus uart speed
    uint8_t 	rec_data[16];    	//modbus recive buffer
    uint8_t 	rec_len; 			//modbus recive data length
}Type_Com_Def;


typedef struct{
	uint8_t 	is_connect;    		//node init state
	uint8_t		is_reverse_direct;	//是否需要反转方向
	uint32_t	single_count;		//单圈值
	uint32_t	mult_count;			//多圈值
	uint32_t	resolution;			//分辨率
	float		angle;				//角度
	float		offset;				//角度偏移
	
	Type_Com_Def	com;			//通信相关结构
	Type_Sens_Type_Def	sens_type;	//传感器类型
}Type_Angle_Encode_Def;


/****************************************function extern**********************************/


extern int xp_angleEncode_init(void);
extern int xp_enc_cacl_offset(uint8_t index, float tarAngle);
extern float xp_angleEncode_get_angle_by_id(uint8_t id, float *angle);
extern int xp_angleEncode_read_angle_by_id(uint8_t id, float *angle);
extern int xp_enc_read_all_encode(void);
extern int xp_angleEncode_debug(char *type,char *fun,char *param);
extern int xp_angleEncode_is_error(uint8_t id);
#endif
//end of the file
